package com.longlong.vo;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "响应参数")
public class ResultBody{
    // 返回的编号
    @ApiModelProperty(value = "响应码",dataType = "int")
    private Integer code;
    // 返回的数据,数据类型N中，
    @ApiModelProperty(value = "响应数据",dataType = "Object")
    private Object data;
    // 返回的信息
    @ApiModelProperty(value = "响应信息",dataType = "String")
    private String message;

    public ResultBody() {
    }

    /**
     * 成功需要返回的数据和信息
     * @param data
     * @param message
     * @return
     */
    public static ResultBody success(Object data, String message) {
        ResultBody r = new ResultBody();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        r.setData(data);
        r.setMessage(message == null ? ResponseEnum.SUCCESS.getMessage() : message);
        return r;
    }

    /**
     * 成功需要返回的信息
     * @param data
     * @return
     */
    public static ResultBody success(Object data) {
        return success(data, null);
    }

    /*
    * 失败需要返回的状态码和信息
    * */
    public static ResultBody fail(Integer code, String message) {
        ResultBody r = new ResultBody();
        r.setCode(code);
        r.setData(null);
        r.setMessage(message);
        return r;
    }

    /**
    * 失败需要枚举类
    * */
    public static ResultBody fail(ResponseEnum responseEnum) {
        ResultBody r = new ResultBody();
        r.setCode(responseEnum.getCode());
        r.setData(null);
        r.setMessage(responseEnum.getMessage());
        return r;
    }





}
